package tpf.designer.pattern.course5.structure_pattern2.flyweight_13.simple;

import org.junit.Test;

public class Client {

    @Test
    public void testSimpleFlyweight(){
        //创建一个享元工厂
        FlyweightFactory factory = new FlyweightFactory();
        //向享元工厂对象请求一个内蕴状态为a的享元对象
        Flyweight fly = factory.factory(new Character('a'));
        //以参量的形式传入一个外蕴状态
        fly.operation("First Call");

        //向享元工厂对象请求一个内蕴状态为b的享元对象
        fly = factory.factory(new Character('b'));
        //以参量的形式传入一个外蕴状态
        fly.operation("Secone Call");

        //向享元工厂对象请求一个内蕴状态为a的享元对象
        fly = factory.factory(new Character('a'));
        //以参量的形式传入一个外蕴状态
        fly.operation("Third Call");

        factory.checkFlyweight();

        Flyweight fly5 = new UnsharedConcreteFlyweight("Unshared");
        fly5.operation("ExtrinsicState-5");
    }
}
